using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;

namespace SlightlyEnhancedContentByQueryWebPartSolution
{
    public class SlightlyEnhancedContentByQueryWebPart : Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart
    {
        public override EditorPartCollection CreateEditorParts()
        {
            EditorPartCollection customep = new EditorPartCollection();
            return new EditorPartCollection(base.CreateEditorParts(), new object[] { new SlightlyEnhancedCQWPEditorPart() });
        }

        public override WebPartVerbCollection Verbs
        {
            get
            {
                try
                {
                    if (!string.IsNullOrEmpty(this.ListName) && !string.IsNullOrEmpty(WebUrl))
                    {
                        using (SPWeb web = SPContext.Current.Site.OpenWeb(this.WebUrl))
                        {
                            SPList list = web.Lists[this.ListName];
                            WebPartVerb openlist = new WebPartVerb(this.ID + "_OpenList", string.Format("javascript:window.open(\"{0}\");", list.DefaultViewUrl));
                            openlist.Text = "Open list";
                            return new WebPartVerbCollection(base.Verbs, new object[] { openlist });
                        }
                    }
                }
                catch
                {
                }

                return base.Verbs;
            }
        }
    }
}
